//
//  AIFAccountBindToPassportManger.m
//  PywSdk
//
//  Created by Jade on 16/4/13.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFAccountBindToPassportManger.h"
#import "PywRSAUtil.h"

@implementation AIFAccountBindToPassportManger

NSString *const AccountBindToPassport_SIGN = @"sign";
NSString *const AccountBindToPassport_TID = @"tid";
NSString *const AccountBindToPassport_GAMEID = @"gameid";
NSString *const AccountBindToPassport_ACCOUNT = @"account";
NSString *const AccountBindToPassport_TOKEN = @"token";
NSString *const AccountBindToPassport_PASSPORT_TOKEN = @"passport_token";
NSString *const AccountBindToPassport_ACCOUNT_PWD = @"account_pwd";
NSString *const AccountBindToPassport_PASSPORT = @"passport";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
/**
 *  方法名称
 *
 *  @return methodName
 */
- (NSString *)methodName
{
    return URL_ACCOUNTBINDTOPASSPORT;
}
- (NSString *)seriviceType
{
    return [PywAppInfo sharedAppInfo].seriviceType;
}

/**
 *  请求类型
 *
 *  @return request type
 */
- (ETAPIManagerRequestType)requestType
{
    return ETAPIManagerRequestTypePost;
}

#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager{
    
    NSString * gameid = [PywAppInfo sharedAppInfo].gameId;
    
    NSString *tid = [[PywAppInfo sharedAppInfo] tid];
    NSString * apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    
    NSString *sign = [NSString stringWithFormat:@"%@%@",gameid,apiSecret2];
    sign = [PywCipherUtils md5:sign];
    
    NSString *passport = [PywPlatformMain sharedPlatformMain].passport;
    NSString *account = self.account;
    NSString *account_pwd = [PywRSAUtil encryptString:self.account_pwd];
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    // 判断性 传Token
    if ([PywPlatformMain sharedPlatformMain].accountType == 1) {
        
        NSString *passport_token = [PywPlatformMain sharedPlatformMain].passport_Token;
        [param setObject:passport_token forKey:AccountBindToPassport_PASSPORT_TOKEN];
    } else {
        
        NSString *token = [PywPlatformMain sharedPlatformMain].token;
        [param setObject:token forKey:AccountBindToPassport_TOKEN];
    }
    [param setObject:passport forKey:AccountBindToPassport_PASSPORT];
    [param setObject:account forKey:AccountBindToPassport_ACCOUNT];
    [param setObject:account_pwd forKey:AccountBindToPassport_ACCOUNT_PWD];
    [param setObject:gameid forKey:AccountBindToPassport_GAMEID];
    [param setObject:tid forKey:AccountBindToPassport_TID];
    [param setObject:sign forKey:AccountBindToPassport_SIGN];
    return param;
}



#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}
@end
